<?php
namespace app\admin\controller;

use think\Controller;
use think\Log;
use think\Exception;

class Comment extends Base
{

    /**
     * 获取评论列表
     * @author wcy
     * @version 2017年7月10日16:49:18
     */
    public function commentList(){
        try{
            if($this->request->isAjax()||$this->request->isPost()){
                $data = $this->deDataTablesJson();
                $draw=$data['draw'];
                $start=$data["start"];
                $length=$data["length"];
                $search="";
                if(!empty($_POST["search"])){
                    $search=$_POST["search"];
                }
                $data=model("Comment")->commentList($search,$start,$length);
                if(!$data){
                    return json(["draw"=>$draw,"recordsTotal"=>0,"recordsFiltered"=>0,"data"=>[]]);
                }else{
                    return json(["draw"=>$draw,"recordsTotal"=>$data["count"],"recordsFiltered"=>$data["count"],"data"=>$data["data"]]);
                }
            }else{
                return view("commentlist");
            }
        }catch (Exception $e){
            Log::record($e->getMessage());
            return false;
        }
    }
    /**
     * 修改评论状态
     * @author wcy
     * @version 2017年7月11日09:42:21
     */
    public function editCommentStatus(){
        try{
            $id=input("post.id");
            $data["status"]=input("post.status");
            $res=model("Comment")->editComment($id,$data);
            if($res!==false){
                return json(["code"=>1,"msg"=>"修改成功"]);
            }else{
                return json(["code"=>2,"msg"=>"修改失败"]);
            }
        }catch (Exception $e){
            Log::record($e->getMessage());
            return json(["code"=>2,"msg"=>"修改失败"]);
        }
    }
}